﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

using LINQSamples.Data;

namespace Web.Samples
{
    public partial class Count : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindQuery();
            this.BindImperative();
        }

        private void BindQuery()
        {
            var query = from p in Product.GetProducts()
                        select p;

            this.litQueryResults.Text = string.Format("Total Items: {0}<br />\n", query.Count());
            this.litQueryResults.Text += string.Format("Total Items starting with 'A': {0}", query.Count(p => p.Name.StartsWith("A")));
        }

        private void BindImperative()
        {
            this.litImperativeResults.Text = string.Format("Total Items: {0}<br />\n", Product.GetProducts().Count());
            this.litImperativeResults.Text += string.Format("Total Items starting with 'A': {0}<br />\n", Product.GetProducts().Count(p => p.Name.StartsWith("A")));
        }
    }
}
